﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using PDO.DataPersistence.Core;
using PDO.DataPersistence.ServiceProvider;
using PDO.UI.Core;
using PDO.Utilities;
using NorthwindDataModel;

namespace NorthwindApp
{
    public class EmployeePM : BasePM
    {
        private PersistableDataObjectList<Employee> _employeeList;
        private Employee _currentEmployee;

        public PersistableDataObjectList<Employee> EmployeeList
        {
            get
            {
                if (null == _employeeList)
                {
                    _employeeList = Employee.GetAll();
                }
                return _employeeList;
            }
            set { _employeeList = value; }
        }

        public Employee CurrentEmployee
        {
            get { return _currentEmployee; }
            set { _currentEmployee = value; }
        }

        public void AddNewEmployee()
        {
            EmployeeList.Add(new Employee() { LastName = "<new>" });
        }

        public void DeleteSelectedEmployee()
        {
            Employee e = GetCurrentListItem(EmployeeList) as Employee;
            if (e != null)
            {
                EmployeeList.Remove(e);
            }
        }
    }
}
